package implementation;

import protocol.Query;
import protocol.State;
import protocol.StateObject;

public class DateHandler {

	public static void handleDate(StateObject nextState, Query query) {
		String standardPrompt = "SpecifyDate";
		String helpPrompt = "DateHelp";
		ExecUtils.playPrompt(standardPrompt, nextState);
		
		boolean receivedInput = false;
		while(!receivedInput){
			ExecUtils.getUserInput(query, "gram_date");
			//user provided a directive
			if (query.getShortConf() != null) {
				String response = query.getShortConf().trim().toLowerCase();
				if (response.equals("assistance"))
					ExecUtils.playPrompt(helpPrompt, nextState);
				else if (response.equals("goback") || response.equals("go back")) {
					ExecUtils.playPrompt(response, nextState);
					receivedInput = true;
					nextState.setState(State.AWAYTEAMCONF);
				}
				else if(response.equals("start over") || response.equals("startover")) {
					ExecUtils.playPrompt(response, nextState);
					receivedInput = true;
					nextState.setState(State.NUMTIX);
				}
				query.voidTransaction();
			} 
			//user provided desired input
			else if (query.dateIsNew()) {
				receivedInput = true;
				nextState.setState(State.AWAYTEAMCONF);
			}
			//user provided no useful input
			else {
				query.voidTransaction();
				ExecUtils.playPrompt(helpPrompt, nextState);
			}
		}
	}

}
